package sample.stock;

import android.app.Activity;
import android.os.Bundle;
import android.view.Window;
import android.webkit.WebChromeClient;
import android.webkit.WebView;
import android.webkit.WebViewClient;

public class ChartView extends Activity {
    private WebView webView = null;
    private String open_price = "";
    private String high_price = "";
    private String low_price = "";
    private String close_price = "";
    private String volumes = "";
    final Activity activity = this;
	 
    @Override
    public void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);
        this.getWindow().requestFeature(Window.FEATURE_PROGRESS);
        setContentView(R.layout.areachart);
        
        webView = (WebView)findViewById(R.id.webview);
        webView.getSettings().setJavaScriptEnabled(true);
        
        webView.setWebChromeClient(new WebChromeClient() {
            public void onProgressChanged(WebView view, int progress)
            {
                activity.setTitle("Loading...");
                activity.setProgress(progress * 100);
 
                if(progress == 100)
                    activity.setTitle("Chart Views");
            }
        });
        
        webView.setWebViewClient(new WebViewClient() {
            @Override
            public void onReceivedError(WebView view, int errorCode, String description, String failingUrl)
            {
                // Handle the error
            }
 
            @Override
            public boolean shouldOverrideUrlLoading(WebView view, String url)
            {
                view.loadUrl(url);
                return true;
            }
        });
        
        Bundle extras = getIntent().getExtras(); 
        open_price = extras.getString("open_price");
        high_price = extras.getString("high_price");
        low_price = extras.getString("low_price");
        close_price = extras.getString("close_price");
        volumes = extras.getString("volumes");
        
        String url = "http://chart.apis.google.com/chart?cht=lc&chs=350x200&chd=t:" + open_price + "&chxr=1,0,30&chds=0,30&chco=4d89f9&chxt=x,y&chxl=0:|Mon|Tue|Wed|Thu|Fri|Sat|Sun&chls=3,1,0&chm=d,4d89f9,0,0,12,0|d,4d89f9,0,1,12,0|d,4d89f9,0,2,12,0|d,4d89f9,0,3,12,0|d,4d89f9,0,4,12,0|d,4d89f9,0,5,12,0|d,4d89f9,0,6,12,0&chg=0,6.67,5,5";
        //String url = "http://chart.apis.google.com/chart?cht=bvg&chs=350x300&chd=t:" + volumes + "&chxr=1,0,40&chds=0,40&chco=ff0000|ffa000|00ff00&chbh=65,0,35&chxt=x,y,x&chxl=0:|High|Medium|Low|2:||Task+Priority||&chxs=2,000000,12&chtt=Tasks+on+my+To+Do+list&chts=000000,20&chg=0,25,5,5";
       
        webView.loadUrl(url);
    }
}
